﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Fashion.Models;
using System.Text;

namespace Fashion.Controllers
{
    [HandleError]
    public class HomeController : ThemeController
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Contact()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Contact(Contact model)
        {
            string productKeyword = Request.Form["ctl00$keyword"];

            if (!string.IsNullOrEmpty(productKeyword))
                return RedirectToAction("Basic", "Search", new { keyword = productKeyword });

            string message = "There are a few errors";

            if (ModelState.IsValid)
            {
                message = "Thanks! We'll get back to you soon.";
            }

            if (Request.IsAjaxRequest())
            {
                return new JsonResult { ContentEncoding = Encoding.UTF8, Data = new { success = true, message = message } };
            }

            TempData["Message"] = message;

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(FormCollection form)
        {
            string productKeyword = form["ctl00$keyword"];

            return RedirectToAction("Basic", "Search", new { keyword = productKeyword });
        }
    }
}
